import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path(.*)',
    component: () => import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () => import('@/views/login/auth-redirect'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () => import('@/views/error-page/401'),
  hidden: true
},
{
  path: '/',
  component: Layout,
  redirect: '/Home',
  children: [{
    path: 'home',
    component: () => import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: {
      title: '首页',
      icon: 'dashboard',
      affix: true
    }
  }]
},
{
  path: '/documentation',
  component: Layout,
  children: [{
    path: 'index',
    component: () => import('@/views/documentation/index'),
    name: '相关文档',
    meta: {
      title: '相关文档',
      icon: 'documentation'
    }
    // , affix: true    设置tabs标签是否固定
  }]
},
// {
//   path: '/guide',
//   component: Layout,
//   redirect: '/guide/index',
//   children: [
//     {
//       path: 'index',
//       component: () => import('@/views/guide/index'),
//       name: 'Guide',
//       meta: { title: 'Guide', icon: 'guide', noCache: true }
//     }
//   ]
// },
// {
//   path: '/profile',
//   component: Layout,
//   redirect: '/profile/index',
//   hidden: true,
//   children: [
//     {
//       path: 'index',
//       component: () => import('@/views/profile/index'),
//       name: 'Profile',
//       meta: { title: 'Profile', icon: 'user', noCache: true }
//     }
//   ]
// }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  //  新增测试 start
  {
    path: '/emp',
    component: Layout,
    redirect: '/emp/epmsIfon',
    alwaysShow: true,
    name: '用户管理',
    meta: {
      title: '用户管理',
      icon: 'star'
    },
    children: [{
      path: 'epmsIfon',
      component: () => import('@/views/emp/index'),
      name: '员工信息',
      meta: {
        title: '员工信息'
      }
    },
    {
      path: 'epmsIfon1',
      component: () => import('@/views/emp/index1'),
      name: '部门管理',
      meta: {
        title: '部门管理'
      }
    },
    {
      path: 'epmgk',
      component: () => import('@/views/emp/empgk'),
      name: '员工概况',
      meta: {
        title: '员工概况'
      }
    },
    {
      path: 'jobTransferApply',
      component: () => import('@/views/emp/jobTransferApply'),
      name: '调岗申请',
      meta: {
        title: '调岗申请'
      }
    },
    {
      path: 'abnormalRecord',
      component: () => import('@/views/emp/abnormalRecord'),
      name: '异动记录',
      meta: {
        title: '异动记录'
      }
    },
    {
      path: 'abnormalApproval',
      component: () => import('@/views/emp/abnormalApproval'),
      name: '异动审批',
      meta: {
        title: '异动审批'
      }
    },

    {
      path: 'edit', // /:id(\\d+)
      component: () => import('@/views/emp/edit'),
      name: '信息编辑',
      meta: {
        title: '信息编辑',
        noCache: true,
        activeMenu: '/emp/index'
      },
      hidden: true
    }
      // {
      //   path: 'EasyProcess',
      //   component: () => import('@/views/emp/test'),
      //   name: '流程设计',
      //   meta: {
      //     title: '流程设计',
      //     noCache: true,
      //     activeMenu: '/emp/index'
      //   },
      //   hidden: false
      // }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/siteInfo',
    children: [{
      path: '/siteInfo',
      component: () => import('@/views/webSite/siteInfo'),
      name: '基本信息',
      meta: {
        title: '基本信息',
        icon: 'star'
      },
    }
    // {
    //   path: 'hyNews',
    //   component: () => import('@/views/articletest/index1'),
    //   name: '行业发展动态',
    //   meta: {
    //     title: '行业发展动态'
    //   }

    // },
      // {
      //   path: 'edit1', // /:id(\\d+)
      //   component: () => import('@/views/articletest/edit1'),
      //   name: '文章编辑',
      //   meta: {
      //     title: '文章编辑',
      //     noCache: true,
      //     activeMenu: '/articletest/index1'
      //   },
      //   hidden: true
      // },
    // 文章新增
      // {
      //   path: 'add', // /:id(\\d+)
      //   component: () => import('@/views/articletest/edit1'),
      //   name: '文章新增',
      //   meta: {
      //     title: '文章新增',
      //     noCache: true,
      //     activeMenu: '/articletest/index1'
      //   },
      //   hidden: true
      // }
    ]
  },
  // 考勤
  {
    path: '/kaoq',
    component: Layout,
    redirect: '/kaoq/kaoqIfon',
    alwaysShow: true,
    name: '考勤管理',
    meta: {
      title: '考勤管理',
      icon: 'star'
    },
    children: [{
      path: 'kaoqSq',
      component: () => import('@/views/kaoqin/index1'),
      name: '考勤申请',
      meta: {
        title: '考勤申请'
      }
    },

    {
      path: 'edit', // /:id(\\d+)
      component: () => import('@/views/kaoqin/sqing'),
      name: '申请',
      meta: {
        title: '申请',
        noCache: true
        // activeMenu: '/emp/index'
      },
      hidden: true
    },
    {
      path: 'rili', // /:id(\\d+)
      component: () => import('@/views/kaoqin/rili'),
      name: '日志',
      meta: {
        title: '日志',
        noCache: true
        // activeMenu: '/emp/index'
      }

    }
      // {
      //   path: 'EasyProcess',
      //   component: () => import('@/views/emp/test'),
      //   name: '流程设计',
      //   meta: {
      //     title: '流程设计',
      //     noCache: true,
      //     activeMenu: '/emp/index'
      //   },
      //   hidden: false
      // }
    ]
  },
  {
    path: '/articletest',
    component: Layout,
    redirect: '/articletest/hyNews',
    alwaysShow: true,
    name: '动态咨询',
    meta: {
      title: '动态咨询',
      icon: 'star'
    },
    children: [{
      path: 'News',
      component: () => import('@/views/articletest/index1'),
      name: '新闻动态',
      meta: {
        title: '新闻动态'
      }
    },
    {
      path: 'hyNews',
      component: () => import('@/views/articletest/index1'),
      name: '行业发展动态',
      meta: {
        title: '行业发展动态'
      }

    },
    // {
    //   path: 'edit/:id(\\d+)',
    //   component: () => import('@/views/test/edit'),
    //   name: '编辑页',
    //   meta: { title: '编辑页', noCache: true, activeMenu: '/test/index' },
    //   hidden: true
    // },
    {
      path: 'edit1', // /:id(\\d+)
      component: () => import('@/views/articletest/edit1'),
      name: '文章编辑',
      meta: {
        title: '文章编辑',
        noCache: true,
        activeMenu: '/articletest/index1'
      },
      hidden: true
    },
    // 文章新增
    {
      path: 'add', // /:id(\\d+)
      component: () => import('@/views/articletest/edit1'),
      name: '文章新增',
      meta: {
        title: '文章新增',
        noCache: true,
        activeMenu: '/articletest/index1'
      },
      hidden: true
    }
    ]
  },
  // 预览文章
  {
    path: '/preview', // /:id(\\d+)
    component: () => import('@/views/articletest/ArticleDetail'),
    name: '文章查看',
    meta: {
      title: '文章查看',
      noCache: true
    },
    hidden: true
  },
  {
    path: '/bpm',
    component: Layout,
    redirect: '/bpm/index',
    alwaysShow: true,
    name: '流程管理',
    meta: {
      title: '流程管理',
      icon: 'star'
    },
    children: [{
      path: 'index',
      component: () => import('@/views/lcsj/processList'),
      name: '流程列表',
      meta: {
        title: '流程列表'
      }
    },
    // {
    //   path: 'test',
    //   component: () => import('@/views/lcsj/test1'),
    //   name: '流程',
    //   meta: {
    //     title: '流程'
    //   }
    // },
    // {
    //   path: 'formDesigner',
    //   component: () => import('@/views/lcsj/formDesigner'),
    //   name: '表单设计',
    //   meta: {
    //     title: '表单设计'
    //   }
    // },
    //
    {
      path: 'formDesigner',
      component: () => import('@/views/lcsj/formDesignerNew'), // 只有基础设置和流程设计
      name: '表单设计',
      meta: {
        title: '表单设计'
      },
      hidden: true
    },
    {
      path: 'designer',
      component: () => import('@/views/lcsj/designer'),
      name: '流程设计',
      meta: {
        title: '流程设计'
      },
      hidden: true
    }

    ]
  },
  {
    path: '/task-mgt',
    component: Layout,
    redirect: '/task-mgt/index',
    alwaysShow: true,
    name: '任务管理',
    meta: {
      title: '任务管理',
      icon: 'star'
    },
    children: [{
      path: 'index',
      component: () => import('@/views/task-mgt/index'),
      name: '任务总览',
      meta: {
        title: '任务总览'
      }
    },
    {
      path: 'performance',
      component: () => import('@/views/task-mgt/performance'),
      name: '绩效预发任务创建',
      meta: {
        title: '绩效预发任务创建'
      },
      hidden: true
    }
    ]
  },
  {
    path: '/Performance-mgt',
    component: Layout,
    redirect: '/Performance-mgt/index',
    alwaysShow: true,
    name: '绩效预发管理',
    meta: {
      title: '绩效预发管理',
      icon: 'star'
    },
    children: [{
      path: 'index',
      component: () => import('@/views/Performance-mgt/index'),
      name: '绩效预发管理',
      meta: {
        title: '绩效预发管理',
        icon: 'star'
      },
      children: [{
        path: 'index1',
        component: () => import('@/views/task-mgt/index'),
        name: '绩效预发管理2',
        meta: {
          title: '绩效预发管理2'
        }
      },

      {
        path: 'performance1',
        component: () => import('@/views/lcsj/designer'),
        name: '绩效预发任务创建',
        meta: {
          title: '绩效预发任务创建'
        }

      }
      ]
    }

    ]
  },

  //  新增测试 end

  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: 'Permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: 'Page Permission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'Directive Permission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: 'Role Permission',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },

  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/icons/index'),
  //       name: 'Icons',
  //       meta: { title: 'Icons', icon: 'icon', noCache: true }
  //     }
  //   ]
  // },

  /** when your routing map is too long, you can split it into small modules **/
  // chartsRouter,
  /* componentsRouter,
  chartsRouter,
  nestedRouter,
  tableRouter,*/
  // tableRouter,

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/list',
  //   name: 'Example',
  //   meta: {
  //     title: 'Example',
  //     icon: 'el-icon-s-help'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/example/create'),
  //       name: 'CreateArticle',
  //       meta: { title: 'Create Article', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/example/edit'),
  //       name: 'EditArticle',
  //       meta: { title: 'Edit Article', noCache: true, activeMenu: '/example/list' },
  //       hidden: true
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/example/list'),
  //       name: 'ArticleList',
  //       meta: { title: 'Article List', icon: 'list' }
  //     }
  //   ]
  // },

  // {
  //   path: '/tab',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/tab/index'),
  //       name: 'Tab',
  //       meta: { title: 'Tab', icon: 'tab' }
  //     }
  //   ]
  // },

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'Error Pages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: '401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: '404', noCache: true }
  //     }
  //   ]
  // },

  // {
  //   path: '/error-log',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'log',
  //       component: () => import('@/views/error-log/index'),
  //       name: 'ErrorLog',
  //       meta: { title: 'Error Log', icon: 'bug' }
  //     }
  //   ]
  // },

  // {
  //   path: '/excel',
  //   component: Layout,
  //   redirect: '/excel/export-excel',
  //   name: 'Excel',
  //   meta: {
  //     title: 'Excel',
  //     icon: 'excel'
  //   },
  //   children: [
  //     {
  //       path: 'export-excel',
  //       component: () => import('@/views/excel/export-excel'),
  //       name: 'ExportExcel',
  //       meta: { title: 'Export Excel' }
  //     },
  //     {
  //       path: 'export-selected-excel',
  //       component: () => import('@/views/excel/select-excel'),
  //       name: 'SelectExcel',
  //       meta: { title: 'Export Selected' }
  //     },
  //     {
  //       path: 'export-merge-header',
  //       component: () => import('@/views/excel/merge-header'),
  //       name: 'MergeHeader',
  //       meta: { title: 'Merge Header' }
  //     },
  //     {
  //       path: 'upload-excel',
  //       component: () => import('@/views/excel/upload-excel'),
  //       name: 'UploadExcel',
  //       meta: { title: 'Upload Excel' }
  //     }
  //   ]
  // },

  // {
  //   path: '/zip',
  //   component: Layout,
  //   redirect: '/zip/download',
  //   alwaysShow: true,
  //   name: 'Zip',
  //   meta: { title: 'Zip', icon: 'zip' },
  //   children: [
  //     {
  //       path: 'download',
  //       component: () => import('@/views/zip/index'),
  //       name: 'ExportZip',
  //       meta: { title: 'Export Zip' }
  //     }
  //   ]
  // },

  // {
  //   path: '/pdf',
  //   component: Layout,
  //   redirect: '/pdf/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/pdf/index'),
  //       name: 'PDF',
  //       meta: { title: 'PDF', icon: 'pdf' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pdf/download',
  //   component: () => import('@/views/pdf/download'),
  //   hidden: true
  // },

  // {
  //   path: '/theme',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/theme/index'),
  //       name: 'Theme',
  //       meta: { title: 'Theme', icon: 'theme' }
  //     }
  //   ]
  // },

  // {
  //   path: '/clipboard',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/clipboard/index'),
  //       name: 'ClipboardDemo',
  //       meta: { title: 'Clipboard', icon: 'clipboard' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://github.com/PanJiaChen/vue-element-admin',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
